//
//  CAttentionDetail.m
//  HCHK_iphone
//
//  Created by yilong zhang on 12-4-27.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CAttentionDetail.h"

@implementation CAttentionDetail

@synthesize m_SearchBar;
@synthesize m_LoadView;
@synthesize m_IsLoading;
@synthesize m_IsPageEnd;
@synthesize m_Scroll;
@synthesize m_TableView;
@synthesize m_Cell;
@synthesize m_FootView;
@synthesize m_lUserID;
@synthesize m_Data;
@synthesize m_nOpType;
@synthesize m_Task;
@synthesize m_NetCnt;
@synthesize m_fLog;
@synthesize m_fLat;
@synthesize m_Condition;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        self.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.0];
        
        //searchbar
        m_SearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 44)];
        m_SearchBar.placeholder = @"当前列表中搜索";
        m_SearchBar.delegate = self;
        [self addSubview:m_SearchBar];
        [m_SearchBar release];
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m_SearchBar.frame.size.width, m_SearchBar.frame.size.height)];
        view.backgroundColor = self.backgroundColor;
        [m_SearchBar insertSubview:view atIndex:[[m_SearchBar subviews] count]-1];
        [view release];
        
        //footview
        m_FootView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 50)];
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        indicator.alpha = 0.0;
        indicator.frame = CGRectMake(0, 0, 25, 25);
        indicator.center= CGPointMake(m_FootView.frame.size.width/2, m_FootView.frame.size.height/2);
        [m_FootView addSubview:indicator];
        [indicator release];
        
        //scrollview
        m_Scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, m_SearchBar.frame.size.height, self.frame.size.width, self.frame.size.height-m_SearchBar.frame.size.height)];
        m_Scroll.backgroundColor = [UIColor clearColor];
        m_Scroll.delegate = self;
        m_Scroll.contentSize = CGSizeMake(m_Scroll.contentSize.width, self.frame.size.height-m_SearchBar.frame.size.height+m_FootView.frame.size.height);
        [self addSubview:m_Scroll];
        [m_Scroll release];
        
        //tableview
        m_TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 0)];
        m_TableView.scrollEnabled = NO;
        m_TableView.backgroundColor = [UIColor clearColor];
        m_TableView.delegate = self;
        m_TableView.dataSource=self;
        [m_Scroll addSubview:m_TableView];
        [m_TableView release];
        
        //footview
        [m_Scroll addSubview:m_FootView];
        [m_FootView release];
        
        //loadview
        [self SetUpLoadView];
        
        m_Data = [[NSMutableArray alloc] init];
        m_lUserID = -1;
        m_nOpType = -1;
        m_IsLoading = NO;
        m_IsPageEnd = NO;
        m_NetCnt = [[CAscCounter alloc] init];
        m_NetCnt.m_nLimit = 6;
        m_NetCnt.m_nOffset= 0;
    }
    return self;
}

-(void)dealloc
{
    [m_Data release];
    
    [super dealloc];
}

//loadview
-(void)SetUpLoadView
{
    m_LoadView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
    m_LoadView.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    m_LoadView.alpha  = 0.0;
    [self addSubview:m_LoadView];
    [m_LoadView release];
    
    UIView *back = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m_LoadView.frame.size.width, m_LoadView.frame.size.height)];
    back.backgroundColor = [UIColor blackColor];
    back.layer.cornerRadius = 5;
    back.alpha = 0.8;
    [m_LoadView addSubview:back];
    [back release];
    
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicator.frame = CGRectMake(0, 0, 25, 25);
    indicator.center= CGPointMake(m_LoadView.frame.size.width/2, m_LoadView.frame.size.height/2);
    [m_LoadView addSubview:indicator];
    [indicator release];
}

-(void)ShowLoadView
{
    [[[m_LoadView subviews] objectAtIndex:1] startAnimating];
    m_LoadView.alpha = 1.0;
}

-(void)HiddenLoadView
{
    m_LoadView.alpha = 0.0;
    [[[m_LoadView subviews] objectAtIndex:1] stopAnimating];
}

//footview
-(void)ShowFootView
{
    UIActivityIndicatorView *indicator = [[m_FootView subviews] objectAtIndex:0];
    [indicator startAnimating];
    indicator.alpha = 1.0;
}

-(void)HiddenFootView
{
    UIActivityIndicatorView *indicator = [[m_FootView subviews] objectAtIndex:0];
    indicator.alpha = 0.0;
    [indicator stopAnimating];
}

-(void)SetAttentionDetailInfo:(NSArray*)data Lat:(CGFloat)lat Log:(CGFloat)log
{
    [self ShowLoadView];
    m_lUserID = [[CUser DefaultUser].U_AID longValue];
    m_fLat = lat;
    m_fLog = log;
    m_NetCnt.m_nLimit  = 6;
    m_NetCnt.m_nOffset = 0;
    [self AddFood:data];
    [self HiddenLoadView];
}

-(void)ClearDatas
{
    m_lUserID = -1;
    m_nOpType = -1;
    [m_Data removeAllObjects];
    
    m_TableView.frame = CGRectMake(m_TableView.frame.origin.x, m_TableView.frame.origin.y, m_TableView.frame.size.width, 0);
    m_FootView.frame  = CGRectMake(m_FootView.frame.origin.x, m_TableView.frame.size.height, m_FootView.frame.size.width, m_FootView.frame.size.height);
    m_Scroll.contentSize = CGSizeMake(m_Scroll.contentSize.width, self.frame.size.height-m_SearchBar.frame.size.height+m_FootView.frame.size.height);
    [m_Scroll setContentOffset:CGPointMake(0, 0)];
    
    [m_TableView reloadData];
    m_NetCnt.m_nLimit = 6;
    m_NetCnt.m_nOffset= 0;
    [[CDownLoadManager DefaultDownLoadManager] CancelTask:m_Task];
    m_SearchBar.text = nil;
    self.m_Task = nil;
    m_IsLoading = NO;
    m_IsPageEnd = NO;
    m_Cell = nil;
    m_fLat = 0.0;
    m_fLog = 0.0;
    [self HiddenLoadView];
    [self HiddenFootView];
}

-(void)AddFood:(NSArray*)datas
{
    m_NetCnt.m_nOffset += [datas count];
    [m_Data addObjectsFromArray:datas];
    
    CGFloat fheight = [datas count]*70;
    m_TableView.frame= CGRectMake(m_TableView.frame.origin.x, m_TableView.frame.origin.y, m_TableView.frame.size.width, m_TableView.frame.size.height+fheight);
    m_FootView.frame = CGRectMake(m_FootView.frame.origin.x, m_TableView.frame.size.height, m_FootView.frame.size.width, m_FootView.frame.size.height);
    fheight = m_TableView.frame.size.height+m_FootView.frame.size.height;
    if (fheight > m_Scroll.frame.size.height+m_FootView.frame.size.height)
        m_Scroll.contentSize = CGSizeMake(m_Scroll.contentSize.width, m_TableView.frame.size.height+m_FootView.frame.size.height);
}

//searchbar
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [m_SearchBar resignFirstResponder];
    
    [self ShowLoadView];
    [self SearchProduct:searchBar.text];
    [self HiddenLoadView];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
    [m_SearchBar resignFirstResponder];
}

//search
-(void)SearchProduct:(NSString*)value
{
    int nCnt = 0;
    for (CProduct *friend in m_Data)
    {
        if (-1 == m_lUserID)
        {
            return;
        }
        else 
        {
            if ([friend.P_Name isEqualToString:value])
            {
                m_Cell.selected = NO;
                NSIndexPath *path = [NSIndexPath indexPathForRow:nCnt inSection:0];
                m_Cell = (CAttentionCell*)[m_TableView cellForRowAtIndexPath:path];
                //[m_TableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
                float fy = m_Cell.tag*70;
                if (fy+m_Scroll.frame.size.height > m_Scroll.contentSize.height)
                    fy = m_Scroll.contentSize.height - m_Scroll.frame.size.height - 50;
                [m_Scroll setContentOffset:CGPointMake(m_Scroll.contentOffset.x, fy) animated:YES];
                m_Cell.selected = YES;
                break;
            }
            ++nCnt;
        }
    }
}

//tableview
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70.0;
}

/*
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 50.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (!m_FootView)
    {
        m_FootView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
        
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        indicator.alpha = 0.0;
        indicator.frame = CGRectMake(0, 0, 25, 25);
        indicator.center= CGPointMake(m_FootView.frame.size.width/2, m_FootView.frame.size.height/2);
        [m_FootView addSubview:indicator];
        [indicator release];
    }
    
    return m_FootView;
}*/

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [m_Data count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [m_SearchBar resignFirstResponder];
    
    //more
    if ((scrollView.contentOffset.y+scrollView.frame.size.height) - scrollView.contentSize.height > 50 && !m_IsLoading)
    {
        [self ShowFootView];
        m_IsPageEnd = YES;
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //Get more datas
    if (!m_IsLoading && m_IsPageEnd)
    {
        m_IsLoading = YES;
        [self CommitGetMoreRequest];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCellStyle style = UITableViewCellStyleDefault;
    if (0 == m_nOpType || 1 == m_nOpType)
    {
        style = UITableViewCellStyleSubtitle;
    }

	CAttentionCell *cell = (CAttentionCell*)[tableView dequeueReusableCellWithIdentifier:@"BaseCell"];
    
    if (!cell)
    {
        cell = [[[CAttentionCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell" Size:CGSizeMake(tableView.frame.size.width, 70)] autorelease];
        cell.textLabel.font = [UIFont systemFontOfSize:12];
        cell.textLabel.numberOfLines = 2;
        cell.detailTextLabel.font = [UIFont systemFontOfSize:11];
        cell.detailTextLabel.numberOfLines = 2;
        [cell.m_EditBtn setTitle:@"添加关注" forState:UIControlStateNormal];
    }
    
    cell.m_Data = [m_Data objectAtIndex:indexPath.row];
    cell.tag = indexPath.row;
    cell.delegate = self;

    //people
    if (0 == m_nOpType)
    {
        //
    }
    //food
    else if (1 == m_nOpType)
    {
        CProduct *product = [m_Data objectAtIndex:indexPath.row];
        product.m_IconView = cell.imageView;
        NSData *data = [product GetProductIcon];
        if (data)
            cell.imageView.image  = [UIImage imageWithData:data];
        else 
            cell.imageView.image  = [UIImage imageNamed:@"dicon.png"];
        cell.textLabel.text       = product.P_Name;
        cell.detailTextLabel.text = product.P_Position;
    }
    //adress 
    else if (2 == m_nOpType)
    {
        CProduct *product = [m_Data objectAtIndex:indexPath.row];
        product.m_IconView = cell.imageView;
        NSData *data = [product GetProductIcon];
        if (data)
            cell.imageView.image  = [UIImage imageWithData:data];
        else 
            cell.imageView.image  = [UIImage imageNamed:@"dicon.png"];
        cell.textLabel.text       = product.P_Name;
        cell.detailTextLabel.text = product.P_Position;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [m_SearchBar resignFirstResponder];
    
    m_Cell.selected = NO;
    m_Cell = (CAttentionCell*)[tableView cellForRowAtIndexPath:indexPath];
    
    [[CRootCtrlManager DefaultRootCtrl].m_ComEdit SetComEditViewInfoEx:[m_Data objectAtIndex:indexPath.row]];
    [[CRootCtrlManager DefaultRootCtrl].m_ComEdit GetDistance:[m_Data objectAtIndex:indexPath.row] Coordinate:[CLocator DefaultLocator].m_Coordinate2D];
    [[CRootCtrlManager DefaultRootCtrl] ShowComEditView];
}

//request
//moredata
-(void)CommitGetMoreRequest
{
    //people
    if (0 == m_nOpType)
    {
        //
    }
    //food
    else if (1 == m_nOpType)
    {
        [self CommitMoreProductRequest];
    }
    //address
    else if (2 == m_nOpType)
    {
        [self CommitMoreAddressRequest];
    }
}

-(void)ReceiveMoreReponse:(NSDictionary *)data
{
    //people
    if (0 == m_nOpType)
    {
        [self ReceiveMorePeopleResponse:data];
    }
    //food
    else if (1 == m_nOpType)
    {
        [self ReceiveMoreProductResponse:data];
    }
    //address
    else if (2 == m_nOpType)
    {
        [self ReceiveMoreAddressReponse:data];
    }
    else {;}
}

//people
-(void)CommitMorePeopleRequest
{
    NSMutableString *request = [NSMutableString string];
    NSString        *url     = URL_MYFRIEND;
    
    CUser *user = [CUser DefaultUser];
    
    [request appendFormat:@"clientID=%@", [AppConfig DefaultAppConfig].m_strUDID];
    [request appendFormat:@"&mobikey=%@", user.U_Token];
    [request appendFormat:@"&sessionid=%@", user.U_Session];
    [request appendFormat:@"&action=%@", OP_GETMYFRIENDS];
    [request appendFormat:@"&cursor=%d", m_NetCnt.m_nOffset];
    [request appendFormat:@"&offset=%d", m_NetCnt.m_nLimit];
    
    self.m_Task = [[CDownLoadManager DefaultDownLoadManager] AddTask:url Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_lUserID] MType:Post UserInfo:[NSNumber numberWithInt:m_nOpType]];
}

-(void)ReceiveMorePeopleResponse:(NSDictionary*)data
{
    id rets = [data objectForKey:@"Resource"];
    if ([rets isKindOfClass:[NSArray class]])
    {
        NSMutableArray *results = [NSMutableArray array];
        CFriend *friend = nil;
        
        for (NSDictionary *data in rets)
        {
            friend = [[CFriend alloc] init];
            [friend SetFriendWithDic:data];
            [results addObject:friend];
            [friend release];
        }
        
        [self AddFood:results];
        [m_TableView reloadData];
        m_Cell.selected = YES;
    }
}

//food
-(void)CommitMoreProductRequest
{
    NSMutableString *request = [NSMutableString string];
    NSString        *url     = nil;
    
    [request appendFormat:@"cursor=%d", m_NetCnt.m_nOffset];
    [request appendFormat:@"&offset=%d", m_NetCnt.m_nLimit];
    [request appendFormat:@"&action=%@", OP_GETSEARCH_PRODUCT];
    [request appendFormat:@"&value=%@", self.m_Condition];
    [request appendFormat:@"&pic_x=%f", [CLocator DefaultLocator].m_Coordinate2D.latitude];
    [request appendFormat:@"&pic_y=%f", [CLocator DefaultLocator].m_Coordinate2D.longitude];
    url = URL_SEARCH;
    
    self.m_Task = [[CDownLoadManager DefaultDownLoadManager] AddTask:url Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_lUserID] MType:Post UserInfo:[NSNumber numberWithInt:1]];
}

-(void)ReceiveMoreProductResponse:(NSDictionary*)data
{
    id rets = [data objectForKey:@"Resource"];
    if ([rets isKindOfClass:[NSArray class]])
    {
        NSMutableArray *results = [NSMutableArray array];
        CProduct *product = nil;
        
        for (NSDictionary *sudic in rets)
        {
            product = [[CProduct alloc] init];
            product.m_nState = 1;
            [product SetProductWithDic:sudic Path:[AppConfig DefaultAppConfig].m_DelImagesPath];
            [results addObject:product];
            [product release];
        }
        
        [self AddFood:results];
        [m_TableView reloadData];
    }
}

//address
-(void)CommitMoreAddressRequest
{
    NSMutableString *request = [NSMutableString string];
    [request appendFormat:@"action=%@", @"getNear"];
    [request appendFormat:@"&pic_x=%f", m_fLat];
    [request appendFormat:@"&pic_y=%f", m_fLog];
    [request appendFormat:@"&pic_distance=%d", 1000];
    [request appendFormat:@"&offset=%d", m_NetCnt.m_nLimit];
    [request appendFormat:@"&cursor=%d", m_NetCnt.m_nOffset];
    
    NSLog(@"\r\n\r\n提交获得地点1km内美食:%@\r\n\r\n", request);
    
    self.m_Task = [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_GET_ADDRESSATTENTION Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_lUserID] MType:Post UserInfo:[NSNumber numberWithInt:2]];
}

-(void)ReceiveMoreAddressReponse:(NSDictionary*)data
{
    id rets = [data objectForKey:@"Resource"];
    if ([rets isKindOfClass:[NSArray class]])
    {
        NSMutableArray *results = [NSMutableArray array];
        CProduct *product = nil;
        
        for (NSDictionary *sudic in rets)
        {
            product = [[CProduct alloc] init];
            [product SetProductWithDic:sudic Path:[AppConfig DefaultAppConfig].m_DelImagesPath];
            [results addObject:product];
            [product release];
        }
        
        [self AddFood:results];
        [m_TableView reloadData];
        m_Cell.highlighted = YES;
    }
}

//addattention
-(void)DidAttentionCellButtonClicked:(UIButton *)sender Cell:(CAttentionCell *)cell
{
    [self AddAttention:nil Cell:cell];
}

-(void)AddAttention:(id)value Cell:(CAttentionCell*)cell
{
    [self CommitAddAttention:m_nOpType Value:cell.m_Data];
    if (1 == m_nOpType)
    {
        NSArray *arr = [NSArray arrayWithObjects:cell.m_Data, nil];
        [[CUserPageCtrl DefaultUserPage].m_AttentionData AddAddress:arr];
    }
    [m_Data removeObject:cell.m_Data];
    
    NSIndexPath *path = [NSIndexPath indexPathForRow:cell.tag inSection:0];
    [m_TableView beginUpdates];
    [m_TableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:path, nil] withRowAnimation:YES];
    [m_TableView endUpdates];
    
    m_TableView.frame = CGRectMake(m_TableView.frame.origin.x, m_TableView.frame.origin.y, m_TableView.frame.size.width, m_TableView.frame.size.height-70);
    m_FootView.frame = CGRectMake(m_FootView.frame.origin.x, m_TableView.frame.size.height, m_FootView.frame.size.width, m_FootView.frame.size.height);
    if (m_TableView.frame.size.height > m_Scroll.frame.size.height)
        m_Scroll.contentSize = CGSizeMake(m_Scroll.contentSize.width, m_TableView.frame.size.height+m_FootView.frame.size.height);
    
    [m_TableView reloadData];
}

-(void)CommitAddAttention:(int)index Value:(id)value
{
    CUser *user = [CUser DefaultUser];
    NSMutableString *request = [NSMutableString string];
    
    //people
    if (0 == index)
    {
        CPeople *people = value;
        people.m_nState = 1;
        [request appendFormat:@"action=%@", OP_ADD_ATTENTION];
        [request appendFormat:@"&type=%d", 1];
        [request appendFormat:@"&mobikey=%@", user.U_Token];
        [request appendFormat:@"&sessionid=%@", user.U_Session];
        [request appendFormat:@"&value=%ld", people.m_ID];
        
        NSLog(@"\r\n\r\n关注人:%@\r\n\r\n", request);
        
        [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_ATTENTION_PEOPLE Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_lUserID] MType:Post UserInfo:[NSNumber numberWithInt:3]];
    }
    //food
    else if (1 == index)
    {
        CProduct *product = value;
        product.m_nState  = 1;
        [request appendFormat:@"action=%@", OP_ADD_ATTENTION];
        [request appendFormat:@"&type=%d", 2];
        [request appendFormat:@"&mobikey=%@", user.U_Token];
        [request appendFormat:@"&sessionid=%@", user.U_Session];
        [request appendFormat:@"&value=%@", product.P_Name];
        
        [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_ATTENTION_FOOD Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_lUserID] MType:Post UserInfo:[NSNumber numberWithInt:4]];
    }
    //address
    else if (2 == index)
    {
        CProduct *product = value;
        product.m_nState  = 1;
        [request appendFormat:@"action=%@", OP_ADD_ATTENTION];
        [request appendFormat:@"&type=%d", 2];
        [request appendFormat:@"&mobikey=%@", user.U_Token];
        [request appendFormat:@"&sessionid=%@", user.U_Session];
        [request appendFormat:@"&value=%@", product.P_Name];
        
        [[CDownLoadManager DefaultDownLoadManager] AddTask:URL_ATTENTION_FOOD Sponsor:self PostData:[request dataUsingEncoding:NSUTF8StringEncoding] TimeOut:30 Data:[NSNumber numberWithLong:m_lUserID] MType:Post UserInfo:[NSNumber numberWithInt:5]];
    }
    else {;}
}

-(void)ReceiveAddAttentionReponse:(NSDictionary*)data Type:(int)type
{    
    if (0 == [[data objectForKey:@"Msg_error"] intValue])
    {
        UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"成功添加关注" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [suc show];
        [suc autorelease];
    }
    else 
    {
        UIAlertView *suc = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已经关注过了" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
        [suc show];
        [suc autorelease];
    }
}

//operation
-(void)DidOperationFinished:(COperation *)op Data:(NSData *)data Other:(id)other UserInfo:(id)userinfo
{
    int           type  = [userinfo intValue];
    NSString      *json = nil;
    NSDictionary  *dic  = nil;
    
    if (m_lUserID == [other longValue])
    {
        json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        dic  = [json JSONValue];
        
        if (type < 3)
        {
            [self ReceiveMoreReponse:dic];
        }
        else if (type >= 3)
        {
            [self ReceiveAddAttentionReponse:dic Type:type-3];
        }
        else {;}
        
        [json release];
    }
    
    self.m_Task = nil;
    m_IsLoading = NO;
    m_IsPageEnd = NO;
    [self HiddenLoadView];
    [self HiddenFootView];
}

-(void)DidOperationError:(COperation *)op Error:(NSError *)error Other:(id)other UserInfo:(id)userinfo
{
    if (m_lUserID == [other longValue])
    {
        ;
    }
    
    self.m_Task = nil;
    m_IsLoading = NO;
    m_IsPageEnd = NO;
    [self HiddenLoadView];
    [self HiddenFootView];
}

-(void)DidOperationTimeOut:(COperation *)op Other:(id)other UserInfo:(id)userinfo
{
    if (m_lUserID == [other longValue])
    {
        ;
    }
    
    self.m_Task = nil;
    m_IsLoading = NO;
    m_IsPageEnd = NO;
    [self HiddenLoadView];
    [self HiddenFootView];
}

@end
